$(function () {
    $.ajax({
        url: BigNews.user_detail,
        type: 'get',
        dataType: 'json',
        success: function (backData) {
            console.log(backData);
            $('.nickname').val(backData.data.nickname)
            $('.username').val(backData.data.username)
            $('.password').val(backData.data.password)
            $('.email').val(backData.data.email)
            $('.user_pic').attr('src', backData.data.userPic)
        }
    })
    //1.1 给file表单设置 onchange事件
    $('#exampleInputFile').on('change', function () {
        //1.2 获取选取的文件信息 ： this.files[0]
        let fileIcon = this.files[0];
        //1.3 创建临时url ： URL.createObjectURL()
        let url = URL.createObjectURL(fileIcon);
        //1.4 显示到页面
        $(this).prev().attr('src', url);
        console.log($(this).prev().attr('src'));
    })
    $('.btn-edit').click(function (e) {
        e.preventDefault()
        let fd = new FormData($('form')[0]);
        // console.log(111);
        $.ajax({
            url: BigNews.user_edit,
            type: 'post',
            dataType: 'json',
            data: fd,
            processData: false,
            contentType: false,
            success: function (backData) {
                console.log(backData);
                if (backData.code == 200) {
                    $('.modal-body>p').text(backData.msg)
                    $('#myModal').modal()
                    $('#myModal').on('hidden.bs.modal', function (e) {
                        window.parent.location.reload('./index.html')
                    })
                    //点击确定后执行
                } else {
                    $('.modal-body>p').text(backData.msg)
                    $('#myModal').modal()
                }
            }
        })
    })

})